<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
      xmlns:jsf="http://xmlns.jcp.org/jsf"
      xmlns:pt="http://java.sun.com/jsf/passthrough"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:o="http://omnifaces.org/ui"
      xmlns:iqbs="http://xmlns.jcp.org/jsf/composite/iqbs">
    <h:head>
    </h:head>

    <h:body>
        <ui:composition template="/dataverse_template.xhtml">
            <ui:param name="pageTitle" value="#{FilePage.fileMetadata.dataFile.displayName} - #{FilePage.file.owner.owner.displayName}"/>
            <ui:param name="dataverse" value="#{FilePage.file.owner.owner}"/>
            <ui:param name="showMessagePanel" value="#{true}"/>
            <ui:define name="meta_header">
            <meta name="description" content="#{FilePage.fileMetadata.description}"/>
            </ui:define>
            <ui:remove><!-- We might want dc_meta_header/og_header/jsonld_header at the file level some day.--></ui:remove>
            <ui:define name="body">
                <f:metadata>
                    <f:viewParam name="fileId" value="#{FilePage.fileId}"/>
                    <f:viewParam name="version" value="#{FilePage.version}"/>
                    <f:viewParam name="persistentId" value="#{FilePage.persistentId}"/>
                    <f:viewAction action="#{dataverseSession.updateLocaleInViewRoot}"/>
                    <f:viewAction action="#{FilePage.init}" />
                    <f:viewAction action="#{dataverseHeaderFragment.initBreadcrumbsForFileMetadata(FilePage.fileMetadata)}"/>
                </f:metadata>
                <h:form id="fileForm">
                    <div id="topDatasetBlock" class="row">
                        <div id="actionButtonBlock" class="col-xs-12">
                            <div class="button-block pull-right">
                                <!-- Email/Share Button Group -->
                                <!--<div class="btn-group" id="datasetButtonBar" role="group" jsf:rendered="#{!widgetWrapper.widgetView}">
                                    <p:commandLink class="text-button btn-contact bootstrap-button-tooltip" title="#{bundle['dataset.email.datasetContactBtn']}"
                                                   update=":contactDialog" oncomplete="PF('contactForm').show()" actionListener="#{sendFeedbackDialog.initUserInput}">
                                        <f:setPropertyActionListener target="#{sendFeedbackDialog.userMessage}" value=""/>
                                        <f:setPropertyActionListener target="#{sendFeedbackDialog.userEmail}" value=""/>
                                        <f:setPropertyActionListener target="#{sendFeedbackDialog.messageSubject}" value=""/>
                                        <f:setPropertyActionListener target="#{sendFeedbackDialog.recipient}" value="#{FilePage.fileMetadata.dataFile}"/>
                                        <span class="glyphicon glyphicon-envelope"/> #{bundle['contact.contact']}
                                    </p:commandLink>
                                    <p:commandLink styleClass="text-button btn-share bootstrap-button-tooltip" rendered="#{!FilePage.fileMetadata.datasetVersion.deaccessioned}"
                                                   title="#{bundle['dataset.share.datasetShare']}"
                                                   oncomplete="PF('shareDialog').show();sharrre();">
                                        <span class="glyphicon glyphicon-share"/> #{bundle['share']}
                                    </p:commandLink>
                                </div>-->
                                <p:dialog id="shareDialog" header="#{bundle['dataset.share.datasetShare']}" widgetVar="shareDialog" modal="true"  rendered="#{!FilePage.fileMetadata.datasetVersion.deaccessioned}">
                                    <p class="help-block">#{bundle['dataset.share.datasetShare.tip']}</p>

                                    <div id="sharrre-widget" data-url="#{systemConfig.dataverseSiteUrl}/dataset.xhtml?persistentId=#{FilePage.fileMetadata.datasetVersion.dataset.globalIdString}" data-text="#{bundle['dataset.share.datasetShare.shareText']}"></div>

                                    <div class="button-block">
                                        <button class="btn btn-default" onclick="PF('shareDialog').hide()" type="button">
                                            #{bundle.close}
                                        </button>
                                    </div>
                                </p:dialog>
                                <!-- END: Email/Share Button Group -->
                                
                                <div class="button-container btn-group" jsf:rendered="#{!widgetWrapper.widgetView}">
                                    <!-- Map Data/Set Up Button Block -->
                                    <ui:fragment rendered="#{dataverseSession.user.authenticated and FilePage.canUpdateDataset() 
                                                             and (FilePage.getConfigureTools().size() > 0
                                                             or worldMapPermissionHelper.canUserSeeMapDataButtonFromPage(FilePage.fileMetadata) or worldMapPermissionHelper.canSeeMapButtonReminderToPublishFromPage(FilePage.fileMetadata))}">		
                                        <ui:include src="file-configure-dropdown-fragment.xhtml">
                                            <ui:param name="configureTools" value="#{FilePage.getConfigureTools()}"/>
                                            <ui:param name="fileId" value="#{FilePage.fileMetadata.dataFile.id}"/>
                                            <ui:param name="fileMetadata" value="#{FilePage.fileMetadata}"/>		
                                            <ui:param name="canUpdateDataset" value="#{FilePage.canUpdateDataset()}"/>		
                                        </ui:include>		
                                    </ui:fragment>
                                    <!-- END: Map Data/Set Up Button Block -->
                                    
                                    <!-- Edit Button Group -->
                                    <div class="btn-group" jsf:rendered="#{dataverseSession.user.authenticated
                                                             and permissionsWrapper.canIssueUpdateDatasetCommand(FilePage.fileMetadata.datasetVersion.dataset) 
                                                             and (dataFileServiceBean.hasReplacement(FilePage.fileMetadata.dataFile) or dataFileServiceBean.hasBeenDeleted(FilePage.fileMetadata.dataFile))}">
                                        <p:commandLink styleClass="btn btn-default btn-access" onclick="PF('fileAlreadyReplacedPrevious').show()">
                                            <span class="glyphicon glyphicon-pencil"/> #{bundle['dataset.editBtn']}
                                        </p:commandLink>
                                    </div>
                                    <div class="btn-group" jsf:rendered="#{dataverseSession.user.authenticated
                                                             and permissionsWrapper.canIssueUpdateDatasetCommand(FilePage.fileMetadata.datasetVersion.dataset)
                                                             and !FilePage.lockedFromEdits
                                                             and !(dataFileServiceBean.hasReplacement(FilePage.fileMetadata.dataFile) or dataFileServiceBean.hasBeenDeleted(FilePage.fileMetadata.dataFile))}">
                                        <button type="button" id="editFile" class="btn btn-default btn-access dropdown-toggle" data-toggle="dropdown">
                                            <span class="glyphicon glyphicon-pencil"/> #{bundle['dataset.editBtn']} <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu pull-right text-left" role="menu">
                                            <ui:fragment rendered="#{systemConfig.provCollectionEnabled}">
                                            <!--  Should be FilePage.isLockedFromEdits() ? -->
                                                <li class="#{DatasetPage.lockedFromEdits  ? 'disabled' : ''}">
                                                    <p:commandLink id="fileProvenanceButton"
                                                               update="editProvenancePopup"
                                                               oncomplete="PF('editProvenancePopup').show();bind_bsui_components();">
                                                               <f:actionListener binding="#{provPopupFragmentBean.updatePopupState(fileMetadata, true)}" /> <!--clearProvenanceUpdates() -->
                                                                #{bundle['file.provenance']} 
                                                    </p:commandLink>
                                                </li> 
                                            </ui:fragment>
                                            <li>
                                                <h:outputLink value="/editdatafiles.xhtml?selectedFileIds=#{FilePage.fileMetadata.dataFile.id}&#38;datasetId=#{FilePage.fileMetadata.datasetVersion.dataset.id}&#38;mode=SINGLE&#38;version=#{FilePage.version}">
                                                    <h:outputText id="editFile-Multi-Link" value="#{bundle['file.dataFilesTab.metadata.header']}"/>
                                                </h:outputLink>
                                            </li>
                                            <ui:fragment rendered="#{!settingsWrapper.publicInstall}">
                                                <ui:fragment rendered="#{!FilePage.fileMetadata.dataFile.filePackage and !FilePage.fileMetadata.restricted}">
                                                    <li>
                                                        <p:commandLink onclick="PF('accessPopup').show()">
                                                            <h:outputText value="#{bundle['file.restrict']}"/>
                                                        </p:commandLink>
                                                    </li>
                                                </ui:fragment>
                                                <ui:fragment rendered="#{!FilePage.fileMetadata.dataFile.filePackage and FilePage.fileMetadata.restricted}">
                                                    <li>
                                                        <p:commandLink update="@form" actionListener="#{FilePage.restrictFile(false)}">
                                                            <h:outputText value="#{bundle['file.unrestrict']}"/>
                                                        </p:commandLink>
                                                    </li>
                                                </ui:fragment>     
                                            </ui:fragment>
                                            <ui:fragment rendered="#{FilePage.fileMetadata.dataFile.released and FilePage.draftReplacementFile == false and !FilePage.fileMetadata.dataFile.filePackage}">                                        
                                            <li><!-- start: replace file link -->
                                                <h:outputLink value="/editdatafiles.xhtml?mode=SINGLE_REPLACE&#38;datasetId=#{FilePage.fileMetadata.datasetVersion.dataset.id}&#38;fid=#{FilePage.fileMetadata.dataFile.id}&#38;version=#{FilePage.version}">
                                                     <h:outputText value="#{bundle['file.replace']}"/>
                                                </h:outputLink>
                                            <!-- end replace file link --></li>
                                            </ui:fragment>
                                            <ui:fragment rendered="#{ !FilePage.fileMetadata.dataFile.filePackage and ((FilePage.fileMetadata.dataFile.released and FilePage.draftReplacementFile == true) or (!FilePage.fileMetadata.dataFile.released and FilePage.fileMetadata.datasetVersion.dataset.released)) }">                                        
                                            <li><!-- start: already replaced replace file link -->
                                                <p:commandLink title="#{bundle['file.delete']}" onclick="PF('fileAlreadyReplacedDraft').show();">
                                                    <h:outputText value="#{bundle['file.replace']}"/>
                                                </p:commandLink>
                                            <!-- end replace file link --></li>
                                            </ui:fragment>  
                                            <ui:fragment rendered="#{!FilePage.fileMetadata.dataFile.released or !FilePage.fileMetadata.dataFile.filePackage}"> 
                                                <li>
                                                    <p:commandLink title="#{bundle['file.delete']}" onclick="PF('deleteFileConfirmation').show();">
                                                        <h:outputText value= "#{bundle['file.delete']}"/>
                                                    </p:commandLink>
                                                </li>
                                            </ui:fragment>
                                            <ui:fragment rendered="#{!widgetWrapper.widgetView and (worldMapPermissionHelper.canUserSeeMapDataButtonFromPage(FilePage.fileMetadata) or worldMapPermissionHelper.canSeeMapButtonReminderToPublishFromPage(FilePage.fileMetadata))}">
                                            <li>
                                            </li>
                                            </ui:fragment>
                                        </ul>
                                    </div>
                                    <!-- END: Edit Button Group -->
                                </div>
                                
                                <!-- Explore/Download/Request Button Block -->
                                <div class="button-container btn-group" jsf:rendered="#{(!FilePage.fileMetadata.datasetVersion.deaccessioned or 
                                                                                            (FilePage.fileMetadata.datasetVersion.deaccessioned and FilePage.canUpdateDataset())) 
                                                                                             and (!FilePage.fileMetadata.dataFile.filePackage or
                                                                                                   FilePage.fileMetadata.dataFile.filePackage and systemConfig.HTTPDownload)}">
                                    <ui:include src="file-download-button-fragment.xhtml">
                                        <ui:param name="fileMetadata" value="#{FilePage.fileMetadata}"/>
                                        <ui:param name="canUpdateDataset" value="#{FilePage.canUpdateDataset()}"/>
                                        <ui:param name="downloadPopupRequired" value="#{FilePage.downloadPopupRequired}"/>
                                        <ui:param name="requestAccessPopupRequired" value="#{FilePage.requestAccessPopupRequired}"/>
                                        <ui:param name="guestbookResponse" value="#{FilePage.guestbookResponse}"/>
                                        <ui:param name="guestbookResponseService" value="#{FilePage.guestbookResponseService}"/>
                                        <ui:param name="fileDownloadService" value="#{FilePage.fileDownloadService}"/>
                                        <ui:param name="isFilePg" value="true"/>
                                        <ui:param name="lockedFromDownload" value="#{FilePage.lockedFromDownload}"/>
                                        <ui:param name="exploreTools" value="#{FilePage.exploreTools}"/>
                                    </ui:include>
                                </div>
                                <!-- END: Explore/Download/Request Button Block -->
                            </div>
                        </div>
                    </div>
                    <!-- END topDatasetBlock -->
                    <div id="fileImageTitle" class="row">
                        <div class="col-xs-12">
                            <div class="row">
                                <div id="file-title-block" class="col-xs-12 margin-bottom-half">
                                    <!-- Restricted File Icon -->
                                    <span class="glyphicon glyphicon-lock text-danger" jsf:rendered="#{FilePage.fileMetadata.restricted and !(fileDownloadHelper.canDownloadFile(FilePage.fileMetadata))}" />
                                    <span class="icon-unlock text-success" jsf:rendered="#{FilePage.fileMetadata.restricted  and fileDownloadHelper.canDownloadFile(FilePage.fileMetadata) }" />

                                    <!-- Title/Label -->
                                    <h:outputText value="#{FilePage.fileMetadata.label}" styleClass="file-title-label"/>
                                    
                                    <div id="title-label-block" class="margin-top-half">
                                        <h:outputText value="#{bundle['dataset.versionUI.draft']}" styleClass="label label-primary" rendered="#{FilePage.fileMetadata.datasetVersion.draft}"/>
                                        <h:outputText value="#{bundle['dataset.versionUI.inReview']}" styleClass="label label-success" rendered="#{FilePage.fileMetadata.datasetVersion.inReview}"/>
                                        <h:outputText value="#{bundle['dataset.versionUI.unpublished']}" styleClass="label label-warning" rendered="#{!FilePage.fileMetadata.datasetVersion.dataset.released}"/>   
                                        <h:outputText value="#{bundle['dataset.versionUI.deaccessioned']}" styleClass="label label-danger" rendered="#{FilePage.fileMetadata.datasetVersion.deaccessioned}"/>
                                        <!-- DATASET VERSION NUMBER -->
                                        <h:outputText styleClass="label label-default" rendered="#{FilePage.fileMetadata.datasetVersion.released and !(FilePage.fileMetadata.datasetVersion.draft or FilePage.fileMetadata.datasetVersion.inReview)}"
                                                      value="#{bundle['file.DatasetVersion']} #{FilePage.fileMetadata.datasetVersion.versionNumber}.#{FilePage.fileMetadata.datasetVersion.minorVersionNumber}" /> 
                                        <h:outputText styleClass="label label-default" rendered="#{!FilePage.fileMetadata.datasetVersion.released and !(FilePage.fileMetadata.datasetVersion.draft or FilePage.fileMetadata.datasetVersion.inReview)}"
                                                      value="#{bundle['file.DatasetVersion']} #{FilePage.fileMetadata.datasetVersion.versionState}"/>
                                    </div>
                                </div>
                                
                                <div class="col-xs-12">
                                    <div class="row">
                                        <!--<div class="col-sm-9">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <h:outputFormat styleClass="h5" value="#{bundle['file.citation.datafile']}" escape="false" />
                                                </div>
                                                <div class="col-sm-12 citation-block">
                                                     <div class="col-sm-12 #{FilePage.fileMetadata.datasetVersion.deaccessioned ? 'alert alert-danger bg-danger' : 'alert alert-info bg-citation bg-citation-file'}">
                                                        <div class="row">
                                                            <div class="col-sm-12 citation">
                                                                <span id="citation-select-2" onclick="if (event.target) { selectText(event.target); } else{ selectText(this); }">
                                                                    <h:outputText value="#{FilePage.fileMetadata.dataFile.isIdentifierRegistered() ? FilePage.fileMetadata.getDirectFileCitation(true) : FilePage.fileMetadata.getFileCitation(true)}" escape="false"/>
                                                                </span>
                                                                <span class="glyphicon glyphicon-question-sign text-primary" jsf:rendered="#{!FilePage.fileMetadata.datasetVersion.dataset.released}" 
                                                                      data-toggle="tooltip" data-placement="top" data-original-title="#{bundle['dataset.cite.title.released']}"/>
                                                                <span class="glyphicon glyphicon-question-sign text-primary" jsf:rendered="#{FilePage.fileMetadata.datasetVersion.dataset.released and FilePage.fileMetadata.datasetVersion.draft}" 
                                                                      data-toggle="tooltip" data-placement="top" data-original-title="#{bundle['dataset.cite.title.draft']}"/>
                                                            </div>
                                                            <div class="col-sm-6 citation-download vcenter" jsf:rendered="#{!FilePage.fileMetadata.datasetVersion.deaccessioned}">
                                                                <div class="dropdown">
                                                                    <button type="button" class="btn btn-default dropdown-toggle downloadCitation" data-toggle="dropdown">
                                                                        <span class="glyphicon glyphicon-list"/> #{bundle['file.cite.file.downloadBtn']} <span class="caret"></span>
                                                                    </button>
                                                                    <ul class="dropdown-menu" role="menu">
                                                                        <li>
                                                                            <a jsf:id="endNoteLink-2" jsf:action="#{FilePage.fileDownloadService.downloadCitationXML(FilePage.fileMetadata, null, FilePage.fileMetadata.dataFile.isIdentifierRegistered())}" >
                                                                                #{bundle['dataset.cite.downloadBtn.xml']}
                                                                            </a>
                                                                        </li>
                                                                        <li>
                                                                            <a jsf:id="risLink-2" jsf:actionListener="#{FilePage.fileDownloadService.downloadCitationRIS(FilePage.fileMetadata, null, FilePage.fileMetadata.dataFile.isIdentifierRegistered())}">
                                                                                #{bundle['dataset.cite.downloadBtn.ris']}
                                                                            </a>
                                                                        </li>
                                                                        <li>
                                                                            <a jsf:id="bibLink-2" jsf:actionListener="#{FilePage.fileDownloadService.downloadCitationBibtex(FilePage.fileMetadata, null, FilePage.fileMetadata.dataFile.isIdentifierRegistered())}" target="_blank">
                                                                                #{bundle['dataset.cite.downloadBtn.bib']}
                                                                            </a>
                                                                        </li>
                                                                    </ul>
                                                                </div>
                                                            </div>
                                                            <div class="col-sm-6 text-right small text-muted citation-standards vcenter" jsf:rendered="#{!DatasetPage.workingVersion.deaccessioned}">
                                                                <h:outputText value="#{bundle['dataset.cite.standards.tip']}" escape="false"/>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="col-sm-12">
                                                    <p class="help-block">
                                                        <h:outputFormat value="#{bundle['file.citation.notice']}" escape="false">
                                                            <o:param value="#{FilePage.fileMetadata.datasetVersion.dataset.displayName}"/>
                                                        </h:outputFormat>
                                                    </p>
                                                    <h:outputFormat styleClass="h5" value="#{bundle['file.citation.dataset']}" escape="false" />
                                                </div>
                                                <div class="col-sm-12 citation-block no-margin-bottom">
                                                    <div class="col-sm-12 #{FilePage.fileMetadata.datasetVersion.deaccessioned ? 'alert alert-danger bg-danger' : 'alert alert-info bg-citation'}">
                                                        <div class="row">
                                                            <div class="col-sm-12 citation">
                                                                <span class="citation-select" onclick="if (event.target) { selectText(event.target); } else{ selectText(this); }">
                                                                    <h:outputText value="#{FilePage.fileMetadata.datasetVersion.getCitation(true)}" escape="false"/>
                                                                </span>
                                                                <span class="glyphicon glyphicon-question-sign text-primary" jsf:rendered="#{!FilePage.fileMetadata.datasetVersion.dataset.released}" 
                                                                      data-toggle="tooltip" data-placement="top" data-original-title="#{bundle['dataset.cite.title.released']}"/>
                                                                <span class="glyphicon glyphicon-question-sign text-primary" jsf:rendered="#{FilePage.fileMetadata.datasetVersion.dataset.released and FilePage.fileMetadata.datasetVersion.draft}" 
                                                                      data-toggle="tooltip" data-placement="top" data-original-title="#{bundle['dataset.cite.title.draft']}"/>
                                                                <span class="glyphicon glyphicon-question-sign text-primary" jsf:rendered="#{FilePage.fileMetadata.datasetVersion.deaccessioned}" 
                                                                      data-toggle="tooltip" data-placement="top" data-original-title="#{bundle['dataset.cite.title.deassessioned']}"/>
                                                            </div>
                                                            <div class="col-sm-6 citation-download vcenter" jsf:rendered="#{!FilePage.fileMetadata.datasetVersion.deaccessioned}">
                                                                <div class="dropdown">
                                                                    <button type="button" class="btn btn-default dropdown-toggle downloadCitation" data-toggle="dropdown">
                                                                        <span class="glyphicon glyphicon-list"/> #{bundle['dataset.cite.downloadBtn']} <span class="caret"></span>
                                                                    </button>
                                                                    <ul class="dropdown-menu" role="menu">
                                                                        <li>
                                                                            <a jsf:id="endNoteLink" jsf:action="#{FilePage.fileDownloadService.downloadDatasetCitationXML(FilePage.fileMetadata.datasetVersion.dataset)}" >
                                                                                #{bundle['dataset.cite.downloadBtn.xml']}
                                                                            </a>
                                                                        </li>
                                                                        <li>
                                                                            <a jsf:id="risLink" jsf:actionListener="#{FilePage.fileDownloadService.downloadDatasetCitationRIS(FilePage.fileMetadata.datasetVersion.dataset)}">
                                                                                #{bundle['dataset.cite.downloadBtn.ris']}
                                                                            </a>
                                                                        </li>
                                                                        <li>
                                                                            <a jsf:id="bibLink" jsf:actionListener="#{FilePage.fileDownloadService.downloadDatasetCitationBibtex(FilePage.fileMetadata.datasetVersion.dataset)}" target="_blank">
                                                                                #{bundle['dataset.cite.downloadBtn.bib']}
                                                                            </a>
                                                                        </li>
                                                                    </ul>
                                                                </div>
                                                            </div>
                                                            <div class="col-sm-6 text-right small text-muted citation-standards vcenter" jsf:rendered="#{!DatasetPage.workingVersion.deaccessioned}">
                                                                <h:outputText value="#{bundle['dataset.cite.standards.tip']}" escape="false"/>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div id="deaccession-reason-block" class="col-xs-12" jsf:rendered="#{FilePage.fileMetadata.datasetVersion.deaccessioned}">
                                                    <div class="col-xs-12 bg-danger">
                                                        <h5 class="margin-top-half">#{bundle['dataset.deaccession.reason']}</h5>
                                                        <p>#{FilePage.fileMetadata.datasetVersion.versionNote}</p>
                                                        <ui:fragment rendered="#{!empty FilePage.fileMetadata.datasetVersion.archiveNote}">
                                                            <p>#{bundle['dataset.beAccessedAt']} <a href="#{FilePage.fileMetadata.datasetVersion.archiveNote}" target="_blank">#{FilePage.fileMetadata.datasetVersion.archiveNote}</a></p>
                                                        </ui:fragment>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>-->
                                        <div class="col-sm-3">
                                            <!-- Metrics -->
                                            <div id="metrics-block" jsf:rendered="#{!(widgetWrapper.widgetView or FilePage.fileMetadata.dataFile.filePackage or FilePage.fileMetadata.datasetVersion.deaccessioned)}">
                                                <div id="metrics-heading">
                                                    #{bundle['metrics.file.title']}
                                                    <span class="glyphicon glyphicon-question-sign tooltip-icon" data-toggle="tooltip" data-placement="auto top" 
                                                            data-original-title="#{settingsWrapper.makeDataCountEnabled ? bundle['metrics.file.tip.makedatacount'] : bundle['metrics.file.tip.default']}"></span>
                                                </div>
                                                <div id="metrics-body">
                                                    <!-- Classic downloads -->
                                                    <div class="metrics-count-block" jsf:rendered="#{!settingsWrapper.makeDataCountEnabled}">
                                                        <h:outputFormat value="{0} #{bundle['metrics.downloads']}">
                                                            <f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
                                                        </h:outputFormat>
                                                        <span class="glyphicon glyphicon-question-sign tooltip-icon"
                                                              data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.tip']}"></span>
                                                    </div>
                                                    <!-- Make Data Count downloads -->
                                                    <div class="metrics-count-block" jsf:rendered="#{settingsWrapper.makeDataCountEnabled}">
                                                        <h:outputFormat value="{0} #{bundle['metrics.downloads']}">
                                                            <f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
                                                        </h:outputFormat>
                                                        <span class="glyphicon glyphicon-question-sign tooltip-icon"
                                                                data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.tip']}"></span>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- END: Metrics -->
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div id="contentTabs">
                        <!-- Metadata -->
                        <p:tabView id="tabView" widgetVar="content" activeIndex="#{FilePage.selectedTabIndex}">
                            <p:ajax event="tabChange" listener="#{FilePage.tabChanged}" oncomplete="bind_bsui_components();" update="@this" />
                            <p:tab id="accessTab" class="padding-none" title="#{bundle['file.dataFilesTab.dataAccess']}"
                                   rendered="#{settingsWrapper.rsyncDownload and FilePage.fileMetadata.dataFile.filePackage and systemConfig.rsyncDownload
                                        and !FilePage.fileMetadata.getDataFile().getOwner().getStorageIdentifier().startsWith('s3://') }">
                                <ui:include src="file-data-access-fragment.xhtml">
                                    <ui:param name="fileMetadata" value="#{fileMetadata}"/>
                                    <ui:param name="datasetVersion" value="#{FilePage.fileMetadata.datasetVersion}"/>
                                    <!--  Should be FilePage.fileDownloadService ? -->
                                    <ui:param name="fileDownloadService" value="#{DatasetPage.fileDownloadService}"/>
                                </ui:include>
                            </p:tab>
                            <p:tab id="metadataMapTab" class="padding-none" title="#{bundle['file.dataFilesTab.metadata.header']}"
                                   rendered="#{(!FilePage.fileMetadata.datasetVersion.deaccessioned or 
                                                              (FilePage.fileMetadata.datasetVersion.deaccessioned and FilePage.canUpdateDataset()))}">
                                
                                <!-- Add + Edit Metadata Button -->
                                <div class="button-block tab-header margin-bottom text-right">
                                    <h:outputLink styleClass="btn btn-default btn-access #{(FilePage.lockedFromEdits) ? 'disabled' : ''}"
                                                  value="/editdatafiles.xhtml?selectedFileIds=#{FilePage.fileMetadata.dataFile.id}&#38;datasetId=#{FilePage.fileMetadata.datasetVersion.dataset.id}&#38;mode=SINGLE"
                                                  rendered="#{!widgetWrapper.widgetView and (dataverseSession.user.authenticated
                                                     and permissionsWrapper.canIssueUpdateDatasetCommand(FilePage.fileMetadata.datasetVersion.dataset)
                                                     and !(dataFileServiceBean.hasReplacement(FilePage.fileMetadata.dataFile) or dataFileServiceBean.hasBeenDeleted(FilePage.fileMetadata.dataFile)))}"
                                                  disabled="#{FilePage.lockedFromEdits}">
                                        <span class="glyphicon glyphicon-pencil"/> #{bundle['file.dataFilesTab.metadata.addBtn']}
                                    </h:outputLink>
                                    <div class="btn-group" jsf:rendered="#{!widgetWrapper.widgetView and (dataverseSession.user.authenticated
                                                         and permissionsWrapper.canIssueUpdateDatasetCommand(FilePage.fileMetadata.datasetVersion.dataset) 
                                                         and (dataFileServiceBean.hasReplacement(FilePage.fileMetadata.dataFile) or dataFileServiceBean.hasBeenDeleted(FilePage.fileMetadata.dataFile)))}">
                                        <button class="btn btn-default btn-access" onclick="PF('fileAlreadyReplacedPrevious').show()" type="button" disabled="#{FilePage.lockedFromEdits}">
                                            <span class="glyphicon glyphicon-pencil"/> #{bundle['dataset.editBtn']}
                                        </button>
                                    </div>

                                    <!-- Export Button -->
                                    <div class="btn-group" jsf:rendered="#{FilePage.fileMetadata.datasetVersion.dataset.released}">
                                        <button class="btn btn-default btn-export dropdown-toggle" type="button" data-toggle="dropdown">
                                            <span class="glyphicon glyphicon-export"/> #{bundle['dataset.exportBtn']} <span class="caret"/></button>
                                        <ul class="dropdown-menu" role="menu">
                                            <ui:repeat var="exporter" value="#{FilePage.getExporters()}">
                                                <li>
                                                    <h:outputLink value="#{exporter[1]}" target="_blank">
                                                        <h:outputText value="#{exporter[0]}"/>
                                                    </h:outputLink>
                                                </li>  
                                            </ui:repeat>
                                        </ul>
                                    </div>
                                </div>
                                <!-- END: Add + Edit Metadata Button -->
                                
                                <div class="panel panel-default">
                                    <div data-toggle="collapse" data-target="#panelCollapseFMD" class="panel-heading text-info">
                                        #{bundle['file.metadataTab.fileMetadata.header']} &#160;<span class="glyphicon glyphicon-chevron-up"/>
                                    </div>
                                    <div id="panelCollapseFMD" class="collapse in">
                                        <div class="panel-body">
                                            <div class="form-group">
                                                <label for="preview-square" class="col-sm-3 control-label">
                                                    #{bundle['file.metadata.preview']}
                                                </label>
                                                <div id="file-preview-icon-block" class="col-sm-9">
                                                    <div id="border-block" style="border:0;">
                                                        <div id="preview-square">
                                                            <span class="icon-#{dataFileServiceBean.getFileThumbnailClass(FilePage.fileMetadata.dataFile)} text-muted" jsf:rendered="#{!FilePage.isThumbnailAvailable(FilePage.fileMetadata)}"/>
                                                            <p:graphicImage styleClass="img-responsive" value="/api/access/datafile/#{FilePage.fileId}?imageThumb=400" 
                                                                            alt="#{FilePage.fileMetadata.label}" rendered="#{FilePage.isThumbnailAvailable(FilePage.fileMetadata)}"/>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div id="fileCategoriesBlock" class="form-group" jsf:rendered="#{!(empty FilePage.fileMetadata.categoriesByName) or !(empty FilePage.fileMetadata.dataFile.tags)}">
                                                <label for="file-tags" class="col-sm-3 control-label">
                                                    #{bundle['file.metadata.filetags']}
                                                </label>
                                                <div id="file-tags" class="col-sm-9">
                                                    <ui:repeat value="#{FilePage.fileMetadata.categoriesByName}" var="tag" rendered="#{!(empty FilePage.fileMetadata.categoriesByName)}">
                                                        <h:outputText value="#{tag}" styleClass="label label-default"/>
                                                    </ui:repeat>
                                                    <ui:repeat value="#{FilePage.fileMetadata.dataFile.tags}" var="tag">
                                                        <h:outputText value="#{tag.typeLabel}" styleClass="label label-info"/>
                                                    </ui:repeat>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{FilePage.file.identifier != null}">
                                                <label for="metadata_persistentId" class="col-sm-3 control-label">
                                                    #{bundle['file.metadata.persistentId']}
                                                </label>
                                                <div class="col-sm-9">
                                                    #{FilePage.file.getGlobalId()}
                                                </div>
                                            </div>
                                            <!--Only show Public download url if identifier is available -->
                                            <div class="form-group" jsf:rendered="#{FilePage.publiclyDownloadable and !FilePage.fileMetadata.dataFile.filePackage}">
                                                <label class="col-sm-3 control-label">                                                   
                                                   #{bundle['file.metadataTab.fileMetadata.downloadUrl.label']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <p class="help-block">
                                                        <h:outputFormat value="#{bundle['file.metadataTab.fileMetadata.downloadUrl.info']}" escape="false">
                                                            <f:param value="#{systemConfig.guidesBaseUrl}"/>
                                                            <f:param value="#{systemConfig.guidesVersion}"/>
                                                        </h:outputFormat>
                                                    </p>
                                                    <code><h:outputText value="#{FilePage.publicDownloadUrl}"/></code>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{!(empty FilePage.file.unf)}">
                                                <label class="col-sm-3 control-label">
                                                   #{bundle['file.metadataTab.fileMetadata.unf.label']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.file.unf}"/>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{!(empty FilePage.file.checksumValue)}">
                                                <label class="col-sm-3 control-label">                                                   
                                                   #{FilePage.file.tabularData ? FilePage.file.originalChecksumType : FilePage.file.checksumType}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.file.checksumValue}"/>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{FilePage.file.released}">
                                                <label class="col-sm-3 control-label">
                                                   #{bundle['file.metadataTab.fileMetadata.publicationDate.label']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.file.publicationDateFormattedYYYYMMDD}"/>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{!(empty FilePage.file.friendlySize)}">
                                                <label class="col-sm-3 control-label">
                                                   #{bundle['file.metadataTab.fileMetadata.size.label']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.file.friendlySize}"/>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{!(empty FilePage.file.friendlyType)}">
                                                <label class="col-sm-3 control-label">
                                                   #{bundle['file.metadataTab.fileMetadata.type.label']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.file.friendlyType}"/>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{!(empty FilePage.file.dataTable.varQuantity)}">
                                                <label class="col-sm-3 control-label">
                                                   #{bundle['file.metaData.dataFile.dataTab.variables']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.file.dataTable.varQuantity}"/>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{!(empty FilePage.file.dataTable.caseQuantity)}">
                                                <label class="col-sm-3 control-label">
                                                   #{bundle['file.metaData.dataFile.dataTab.observations']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.file.dataTable.caseQuantity}"/>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{!empty FilePage.fileMetadata.directoryLabel}">
                                                <label class="col-sm-3 control-label">
                                                   #{bundle['file.metadataTab.fileMetadata.hierarchy.label']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.fileMetadata.directoryLabel}/"/>
                                                </div>
                                            </div>
                                            <div class="form-group" jsf:rendered="#{!(empty FilePage.fileMetadata.description)}">
                                                <label class="col-sm-3 control-label">
                                                   #{bundle['file.metadataTab.fileMetadata.description.label']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.fileMetadata.description}"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">
                                                   #{bundle['file.metadataTab.fileMetadata.depositDate.label']}
                                                </label>
                                                <div class="col-sm-9">
                                                    <h:outputText value="#{FilePage.file.createDateFormattedYYYYMMDD}"/> 
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </p:tab>
                            <ui:remove>
                                <p:tab id="provenanceTab" title="Provenance" rendered="#{(!FilePage.fileMetadata.datasetVersion.deaccessioned or 
                                                              (FilePage.fileMetadata.datasetVersion.deaccessioned and FilePage.canUpdateDataset()))}">
                                    <!-- Placeholder -->
                                    <em>Coming soon...</em>
                                </p:tab>
                            </ui:remove>
                            <p:tab id="versionsTab" title="#{bundle['file.dataFilesTab.versions']}">
                                <ui:include src="file-versions.xhtml"></ui:include>
                            </p:tab>
                        </p:tabView>
                    </div>

                    <p:dialog id="deleteFileConfirm" styleClass="smallPopUp" header="#{bundle['file.deleteFileDialog.header']}" widgetVar="deleteFileConfirmation" modal="true">
                        <p class="text-warning"><span class="glyphicon glyphicon-warning-sign"/> #{bundle['file.deleteFileDialog.immediate']}</p>
                        <ui:fragment rendered="#{FilePage.fileMetadata.dataFile.owner.released}">
                            <p class="text-warning"><span class="glyphicon glyphicon-warning-sign"/> #{bundle['file.deleteFileDialog.failed.tip']}</p>
                        </ui:fragment>
                        <div class="button-block">
                            <p:commandButton styleClass="btn btn-default" value="#{bundle['file.delete']}" onclick="PF('deleteFileConfirmation').hide()" 
                                             action="#{FilePage.deleteFile()}"/>
                            <button class="btn btn-link" onclick="PF('deleteFileConfirmation').hide()" type="button">
                                #{bundle.cancel}
                            </button>
                        </div>
                    </p:dialog>
                    <p:dialog id="downloadPopup" styleClass="largePopUp" header="#{bundle['file.downloadDialog.header']}" widgetVar="downloadPopup" modal="true">
                         <ui:include src="file-download-popup-fragment.xhtml">
                            <ui:param name="workingVersion" value="#{FilePage.fileMetadata.datasetVersion}"/>
                            <ui:param name="downloadPopupRequired" value="#{FilePage.downloadPopupRequired}"/>
                            <ui:param name="guestbookResponse" value="#{FilePage.guestbookResponse}"/>
                            <ui:param name="guestbookResponseService" value="#{FilePage.guestbookResponseService}"/>
                            <ui:param name="fileDownloadService" value="#{FilePage.fileDownloadService}"/>
                            <ui:param name="lockedFromDownload" value="#{FilePage.lockedFromDownload}"/>
                        </ui:include>
                    </p:dialog>
                    <p:dialog id="downloadPackagePopup" styleClass="smallPopUp" header="#{bundle['packageDownload.title']}" widgetVar="downloadPackagePopup" modal="true">
                         <ui:include src="package-download-popup-fragment.xhtml">
                            <ui:param name="workingVersion" value="#{FilePage.fileMetadata.datasetVersion}"/>
                            <ui:param name="downloadPopupRequired" value="#{FilePage.downloadPopupRequired}"/>
                            <ui:param name="guestbookResponse" value="#{FilePage.guestbookResponse}"/>
                            <ui:param name="guestbookResponseService" value="#{FilePage.guestbookResponseService}"/>
                            <ui:param name="fileDownloadService" value="#{FilePage.fileDownloadService}"/>
                            <ui:param name="lockedFromDownload" value="#{FilePage.lockedFromDownload}"/>
                        </ui:include>
                    </p:dialog>
                    <p:dialog id="requestAccessPopup" styleClass="largePopUp" header="#{bundle['file.requestAccess']}" widgetVar="requestAccessPopup" modal="true">
                        <o:importFunctions type="edu.harvard.iq.dataverse.util.MarkupChecker" />
                        <ui:include src="file-request-access-popup-fragment.xhtml">
                            <ui:param name="workingVersion" value="#{FilePage.fileMetadata.datasetVersion}"/>
                            <ui:param name="fileDownloadService" value="#{FilePage.fileDownloadService}"/>
                        </ui:include>
                    </p:dialog>
                    <p:dialog id="configureToolPopup" styleClass="smallPopUp" header="#{configureFragmentBean.configurePopupToolHandler.externalTool.displayName}" widgetVar="configureToolPopup" modal="true" 
                                rendered="#{dataverseSession.user.authenticated and FilePage.canUpdateDataset()}">
                        <ui:include src="file-configure-popup-fragment.xhtml">
                            <ui:param name="externalTools" value="#{FilePage.getExternalTools()}"/>
                            <ui:param name="canUpdateDataset" value="#{FilePage.canUpdateDataset()}"/>
                        </ui:include>
                    </p:dialog>
                    
                    <ui:include rendered="#{systemConfig.provCollectionEnabled}" src="provenance-popups-fragment.xhtml">
                            <ui:param name="saveInPopup" value="true"/>
                    </ui:include>
                    
                    <!-- Request Access Sign Up/Log In Button -->
                    <p:dialog id="accessGuest" header="#{bundle['file.requestAccess']}" widgetVar="accessSignUpLogIn_popup" modal="true">
                        <p class="help-block">
                            <span class="glyphicon glyphicon-exclamation-sign text-danger"/>&#160;
                            <h:outputFormat styleClass="text-danger" value="#{dataverseHeaderFragment.signupAllowed ? bundle['file.requestAccess.dialog.msg.signup'] : bundle['file.requestAccess.dialog.msg']}" escape="false">
                                <f:param value="#{navigationWrapper.redirectPage}"/>
                                <f:param value="#{dataverseHeaderFragment.getSignupUrl(navigationWrapper.redirectPage)}"/>
                                <f:param value="#{widgetWrapper.widgetView ? '_blank' : '_self'}"/>
                            </h:outputFormat>
                        </p>
                        <div class="button-block">
                            <button class="btn btn-default" onclick="PF('accessSignUpLogIn_popup').hide();PF('blockDatasetForm').hide();" type="button">
                                #{bundle.close}
                            </button>
                        </div>
                    </p:dialog>
                    <p:dialog id="accessPopup" styleClass="smallPopUp" header="#{bundle['file.restrictions']}" widgetVar="accessPopup" modal="true">
                        <p:focus context="accessPopup"/>
                        <p class="help-block">
                            #{bundle['file.restrictions.description']}
                        </p>
                        <ui:fragment rendered="#{FilePage.worldMapPermissionHelper.hasMapLayerMetadata(FilePage.fileMetadata)}">
                        <p class="help-block">
                            <span class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span> #{bundle['file.restrictions.worldmap.warning']}</span>
                        </p>
                        </ui:fragment>
                        <div class="form-horizontal">
                            <div class="form-group">
                                <label for="metadata_TermsAccess" class="col-sm-3 control-label">
                                    #{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess']}
                                    <span class="glyphicon glyphicon-question-sign tooltip-icon"
                                          data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess.title']}"></span>
                                </label>
                                <div class="col-sm-9">
                                    <p:inputTextarea value="#{FilePage.fileMetadata.datasetVersion.termsOfUseAndAccess.termsOfAccess}" autoResize="false" rows="5" styleClass="form-control" widgetVar="inputtoa"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="metadata_RequestAccess" class="col-sm-3 control-label">
                                    #{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess']}
                                    <span class="glyphicon glyphicon-question-sign tooltip-icon"
                                         data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.title']}"></span>
                                </label>
                                <div class="col-sm-9">
                                    <p:selectBooleanCheckbox id="requestAccess" itemLabel="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.enableBtn']}"
                                                             value="#{FilePage.fileMetadata.datasetVersion.termsOfUseAndAccess.fileAccessRequest}" widgetVar="inputfar"/>
                                </div>
                            </div>
                        </div>
                        <div class="button-block">
                            <p:commandButton styleClass="btn btn-default" value="#{bundle.continue}" onclick="PF('accessPopup').hide();" update=":messagePanel" action="#{FilePage.restrictFile(true)}"/>
                            <!--<button class="btn btn-link" onclick="PF('accessPopup').hide();" type="button">
                                #{bundle.cancel}
                            </button>-->
                            <p:commandButton styleClass="btn btn-link" value="#{bundle.cancel}"
                                             onclick="PF('accessPopup').hide();" update="accessPopup" action="#{FilePage.cancelAccessPopup()}"/>
                        </div>
                    </p:dialog>
                    <p:dialog id="fileAlreadyReplacedDraft" styleClass="smallPopUp"
                              header="#{bundle['file.replaced.warning.header']}" widgetVar="fileAlreadyReplacedDraft" modal="true">
                        <p class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"/> #{bundle['file.replaced.warning.draft.warningMessage']}</p>
                        <div class="button-block">
                            <button class="btn btn-default" onclick="PF('fileAlreadyReplacedDraft').hide();" type="button">
                                #{bundle.close}
                            </button>
                        </div>
                    </p:dialog>
                    <p:dialog id="fileAlreadyReplacedPrevious" styleClass="smallPopUp"
                              header="#{bundle['file.replaced.warning.header']}" widgetVar="fileAlreadyReplacedPrevious" modal="true">
                        <ui:fragment rendered="#{dataFileServiceBean.hasReplacement(FilePage.fileMetadata.dataFile) }">
                            <p class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"/> #{bundle['file.replaced.warning.previous.warningMessage']}</p>
                        </ui:fragment>
                        <ui:fragment rendered="#{!dataFileServiceBean.hasReplacement(FilePage.fileMetadata.dataFile)}">
                            <p class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"/> #{bundle['file.alreadyDeleted.previous.warningMessage']}</p>
                        </ui:fragment>
                        <div class="button-block">
                            <button class="btn btn-default" onclick="PF('fileAlreadyReplacedPrevious').hide();" type="button">
                                #{bundle.close}
                            </button>
                        </div>
                    </p:dialog>
                    <p:dialog id="computeAccessDenied" styleClass="smallPopUp" header="#{bundle['dataset.compute.computeBtn']}" widgetVar="computeAccessDeniedPopup" modal="true">
                        <p class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"/> #{bundle['file.compute.fileAccessDenied']}</p>
                        <div class="button-block">
                            <button class="btn btn-default" onclick="PF('computeAccessDeniedPopup').hide();" type="button">
                                #{bundle.close}
                            </button>
                        </div>
                    </p:dialog>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
